package com.example.spinning.service;

import com.example.spinning.bean.SpinningFeeding;
import com.example.spinning.mapper.SpinningFeedingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpinningFeedingService {

    @Autowired
    private SpinningFeedingMapper spinningFeedingMapper;

    //得到投料单信息
    //带有分页功能的展现数据
    public List<SpinningFeeding> getAllSpinningFeeding(Integer page, Integer count) {
        int start = (page - 1) * count;
        return spinningFeedingMapper.getSpinningFeeding(start,count);
    }

    //找到行数
    public int getSpinningFeedingCount() {
        return spinningFeedingMapper.getCountSpinningFeeding();
    }

    //根据条件找到行数
        public int getSpinningFeedingCountByCondition(String date,String batch_no,String num,String composition,String customer){
        return spinningFeedingMapper.getCountSpinningFeedingByCondition(date,batch_no,num,composition,customer);
    }

    //根据id查询投料单信息
    public SpinningFeeding getSpinningFeedingById(long id){
        SpinningFeeding order = spinningFeedingMapper.getSpinningFeedingById(id);
        return order;
    }

    //根据条件模糊查询
    public List<SpinningFeeding> getSpinningFeedingByCondition(Integer page, Integer count, String date, String batch_no, String num, String composition,String customer){
        int start = (page - 1) * count;
        return spinningFeedingMapper.getSpinningFeedingByCondition(start,count,date,batch_no,num,composition,customer);
    }

    //添加投料单信息
    public int addSpinningFeeding(SpinningFeeding order){
        return spinningFeedingMapper.addSpinningFeeding(order);
    }


    //修改
    public int updateSpinningFeeding(SpinningFeeding order){
        return spinningFeedingMapper.updateSpinningFeedingById(order);
    }

    //删除
    public boolean deleteSpinningFeedingByIds(String ids){
        String[] split = ids.split(",");
        int result = spinningFeedingMapper.delSpinningFeedingById(split);
        return result == split.length;
    }


}
